/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package avayajtapirecepcion;

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import javax.telephony.Call;
import javax.telephony.CallEvent;
import javax.telephony.ConnectionEvent;
import javax.telephony.MetaEvent;
import javax.telephony.callcontrol.CallControlConnectionEvent;
import javax.telephony.callcontrol.CallControlConnectionListener;

/**
 *
 * @author AIDALIT
 */
public class ListenerLlamada implements CallControlConnectionListener {
    String url;
    public ListenerLlamada(String url)
    {
        this.url=url;
    }

    public void connectionAlerting(CallControlConnectionEvent event) {
        Call call = event.getCall();
        String callingDeviceID = null;
        String calledDeviceID = null;
        if (event.getCallingAddress() != null) {
            callingDeviceID = event.getCallingAddress().getName();
        }
        if (event.getCalledAddress() != null) {
            calledDeviceID = event.getCalledAddress().getName();
        }
        System.out.println("Incoming call from "
                + callingDeviceID + " to " + calledDeviceID);
        try {
            if (Desktop.isDesktopSupported()) {
                java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
                desktop.browse(new URI(this.url+"?ani="+callingDeviceID));
            }
        } catch (Exception ex) {
            System.out.println("Error al abrir la pagina");
        }
    }

    public void connectionDialing(CallControlConnectionEvent ccce) {

    }

    public void connectionDisconnected(CallControlConnectionEvent ccce) {

    }

    public void connectionEstablished(CallControlConnectionEvent ccce) {

    }

    public void connectionFailed(CallControlConnectionEvent ccce) {

    }

    public void connectionInitiated(CallControlConnectionEvent ccce) {

    }

    public void connectionNetworkAlerting(CallControlConnectionEvent ccce) {

    }

    public void connectionNetworkReached(CallControlConnectionEvent ccce) {

    }

    public void connectionOffered(CallControlConnectionEvent ccce) {

    }

    public void connectionQueued(CallControlConnectionEvent ccce) {

    }

    public void connectionUnknown(CallControlConnectionEvent ccce) {

    }

    public void callActive(CallEvent ce) {

    }

    public void callInvalid(CallEvent ce) {

    }

    public void callEventTransmissionEnded(CallEvent ce) {

    }

    public void singleCallMetaProgressStarted(MetaEvent me) {

    }

    public void singleCallMetaProgressEnded(MetaEvent me) {

    }

    public void singleCallMetaSnapshotStarted(MetaEvent me) {

    }

    public void singleCallMetaSnapshotEnded(MetaEvent me) {

    }

    public void multiCallMetaMergeStarted(MetaEvent me) {

    }

    public void multiCallMetaMergeEnded(MetaEvent me) {

    }

    public void multiCallMetaTransferStarted(MetaEvent me) {

    }

    public void multiCallMetaTransferEnded(MetaEvent me) {

    }

    public void connectionAlerting(ConnectionEvent ce) {

    }

    public void connectionConnected(ConnectionEvent ce) {

    }

    public void connectionCreated(ConnectionEvent ce) {

    }

    public void connectionDisconnected(ConnectionEvent ce) {

    }

    public void connectionFailed(ConnectionEvent ce) {

    }

    public void connectionInProgress(ConnectionEvent ce) {

    }

    public void connectionUnknown(ConnectionEvent ce) {

    }
}
